import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/style/reset.css'
import "@/assets/style/mycss.css"
import go from "@/assets/myjs/overallGo.js"

Vue.use(ElementUI);
Vue.config.productionTip = false
// axios.defaults.baseURL = "http://47.99.38.32:8088/";
axios.defaults.baseURL = "api/";
Vue.prototype.$goto = go;

// const baseUrl = process.env.NODE_ENV === 'development' ? '/api' : ''
// process.env.VUE_APP_BASE_API = '/api';

// 在发送请求前的操作
// 判断是否存在token,如果存在将每个页面header添加token
// axios.interceptors.request.use(function (config) {
//   if (store.state.user.token) {
//     config.headers.common['Authorization'] = "Bearer " + store.state.user.token
//   }
//   return config
// }, function (error) {
//   router.push('/login')
//   return Promise.reject(error)
// })

axios.interceptors.request.use(
  config => {
    // ’‘content-type’: 'application/json’
    // config.headers.ContentType='application/json'
    if (localStorage.getItem('token')) {
      // config.headers.token = localStorage.getItem('token');
      config.headers.Authorization = localStorage.getItem('token');
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  });

// 添加响应拦截器，移除token
// axios.interceptors.response.use(
//   response => {
//     return response;
//   },
//   error => {
//     if (error.response) {
//       switch (error.response.status) {
//         case 401:
//           localStorage.removeItem('token');
//           this.$router.push('/login');
//       }
//     }
//   })



Vue.prototype.$axios = axios;
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
